package com.dundun.SSO.manage.impl;

import com.dundun.SSO.core.impl.BaseServiceImpl;
import com.dundun.SSO.manage.ISsoUserAccountService;
import com.dundun.SSO.manage.dao.SsoUserAccountDao;
import com.dundun.SSO.manage.dao.SsoUserDao;
import com.dundun.SSO.manage.pojo.SsoUser;
import com.dundun.SSO.manage.pojo.SsoUserAccount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.ArrayList;
import java.util.List;

/**********************************************************
 * 版权所有：搜影科技 保留所有权利
 * 创建日期: 2017/5/24 0024 14:24
 * 创建作者: gezhangkai
 * 版    本:
 * 功    能:
 * 最后修改时间:
 * 修改记录:
 ***********************************************************/
@Service
@Transactional
public class SsoUserAccountServiceImpl extends BaseServiceImpl<SsoUserAccount> implements ISsoUserAccountService{

    @Autowired
    private SsoUserDao ssoUserDao;

    @Autowired
    private SsoUserAccountDao ssoUserAccountDao;

    public int saveUser(SsoUserAccount ssoUserAccount) {
        int i = ssoUserAccountDao.save(ssoUserAccount);
        SsoUser ssoUser = new SsoUser();
        ssoUser.setAccount(ssoUserAccount.getAccount());
        i *= ssoUserDao.save(ssoUser);
        return i;
    }

    public SsoUserAccount selectOneByUsername(String name) {
        Example example = new Example(SsoUserAccount.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("name",name);
        List<SsoUserAccount> ssoUserAccountList = new ArrayList<SsoUserAccount>();
        ssoUserAccountList = selectByExample(example);
        if(!ssoUserAccountList.isEmpty()){
            return ssoUserAccountList.get(0);
        }
        return null;
    }
}
